<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/30/0030
 * Time: 13:35
 */

namespace app\sports_admin\controller;

use app\exception\ParameterException;
use app\sports_admin\model\PaySet as PaySetModel;
use think\Request;
use app\sports_admin\service\PaySet as PaySetService;
use app\sports_admin\vaildate\PaySet as PaySetVaildate;
class PaySet extends Base
{
    protected $beforeActionList = [
        'isAdmin'=>['only'=>'index,updatepayset'],
        'operationSelect'=>['only'=>'index,updatepayset']
    ];
    //支付设置首页
    public function index()
    {

        return view('index');
    }
    /**
     * 支付设置列表
     */
    public function getList()
    {
        $request = Request::instance()->param();
        $page = intval($request['page']);
        $rows = intval($request['rows']);
        $info = PaySetModel::getList($page,$rows);
        return json($info);
    }
    /**
     * 支付设置
     */
    public function add()
    {
        return view('add');
    }
    /**
     * 添加支付说明
     */
    public function insert()
    {
        (new PaySetVaildate())->insert();
        $params = Request::instance()->param();
        $bool = PaySetModel::create(['title'=>$params['title'],'content'=>htmlspecialchars($params['content'])]);
        if(!$bool){
            throw new ParameterException(['msg'=>'添加失败','errorCode'=>400]);
        }
        return json(['msg'=>'添加成功','code'=>200]);
    }
    /**
     * 修改支付配置信息
    */
    public function updatePaySet(Request $request)
    {
        if($request->isAjax()){
            $bool = PaySetService::updatePaySetInfo();
            if($bool){
                return json(['code'=>200,'msg'=>'配置成功']);
            }
        }
    }
}